package com.project.service.impl;

import com.project.bean.SellCarBean;
import com.project.mapper.IProductMapper;
import com.project.service.ISellCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
@Service
public class SellCarService implements ISellCarService {
    @Autowired
    private IProductMapper mapper;
    @Override
    public void sell(int productId, Map<Integer, SellCarBean> sellCarMap) {
        if(sellCarMap.containsKey(productId) == false){
            SellCarBean sellCar = new SellCarBean();
            sellCar.setNum(1);
            sellCar.setProduct(mapper.findById(productId));
            sellCarMap.put(productId, sellCar);
        }else {
            SellCarBean sellCar = sellCarMap.get(productId);
            sellCar.setNum(sellCar.getNum() + 1);
        }
    }

    @Override
    public void remove(int productId, Map<Integer, SellCarBean> sellCarMap) {
        sellCarMap.remove(productId);
    }

    @Override
    public void updateNum(int productId, Map<Integer, SellCarBean> sellCarMap, int num) {
        SellCarBean sellCar = sellCarMap.get(productId);
        sellCar.setNum(num);
    }
}
